using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Diagnostics;
namespace Test {
	class MisRoutes {
		static void MainX() {
			DAL dal=new DAL("pon-wpsq16-db","directory");
			DirectoryInfo di=new DirectoryInfo("mis");
			FileInfo[] files=di.GetFiles("*.txt");
			foreach(FileInfo file in files)
			{
				StringBuilder sb=new StringBuilder();
				DateTime dat=file.LastWriteTime;
				string[] lines=File.ReadAllLines(file.FullName);
				foreach(string line in lines)
				{
					string[] arr=line.Split(',');
					string sendAt=arr[0];
					string Cust=arr[1];
					string Inv=arr[2];
					string DelivNoteNo=dal.Scalar("SELECT DeliveryNoteNumber FROM dirOldParcelDetail(NOLOCK)WHERE CustomerNumber='{0}' AND InvoiceNumber='{1}' union SELECT DeliveryNoteNumber FROM dirParcelDetail(NOLOCK)WHERE CustomerNumber='{0}' AND InvoiceNumber='{1}'",Cust,Inv) as string;

					if(DelivNoteNo==null)
						continue;
					DataTable data1=dal.Query("SELECT LightLarge,depot,warehouse,ParcelType FROM dirOldParcel(NOLOCK)WHERE DeliveryNoteNumber='{0}'",DelivNoteNo);
					Debug.Assert(data1.Rows.Count==1);
					string LightLarge=data1.Rows[0]["LightLarge"].ToString();
					string depot=data1.Rows[0]["depot"].ToString();
					string warehouse=data1.Rows[0]["warehouse"].ToString();
					string ParcelType=data1.Rows[0]["ParcelType"].ToString();
					sb.AppendFormat("INSERT INTO DirMisRoutes(SentAt,CustomerNumber,InvoiceNumber,DeliveryNoteNumber,LightLarge,Depot,Warehouse,inserted,ParcelType)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}',convert(datetime,'{7:yyyy-MM-dd HH:mm}',20),'{8}'){9}",sendAt,Cust,Inv,DelivNoteNo,LightLarge,depot,warehouse,dat,ParcelType,Environment.NewLine);

				}
				//dal.NonQry(sb.ToString());


			}
		}
	}
}
